<template>
  <div class="common-body-wrapper">
    <search-header
      single-width="130"
      :searchList="searchList"
      @changeHeight="toRetTable"
      @confirmSearch="toSearch"
    ></search-header>
    <multi-fun-table
      :sortColumn="notFormatColumn"
      :orderType="sortType"
      :fixed-cols="fixedCols"
      :is-reset-table="isResetTable"
      :theads-info="theadsInfo"
      :tbodys-info="tbodysInfo"
      @handleMultiCheck="handleMultiCheck"
      @handleSortColumn="handleSortColumn"
      @searchFn="getList"
      @getNextPage="getNextPage"
    >
      <!--按钮-->
      <div class="operate-btn-group" slot="operateBtnGroup">
        <a
          class="ake_btn ake_btn_text"
          v-if="isPermmited('PLATFORM:ROLE:SAVE')"
          @click.prevent="toOpenAddRoleDialog()"
        >新增角色</a>
        <a
          class="ake_btn ake_btn_text"
          v-if="isPermmited('PLATFORM:ROLE:DEL')"
          @click.prevent="toOpenDeleteRole(null)"
        >批量删除</a>
      </div>

      <!--普通列-->
      <template slot="tdCell" slot-scope="props">
        <el-table-column
          :fixed="props.fixed"
          :label="props.label"
          :min-width="props.minWidth"
          :width="props.width"
          :prop="props.prop"
          :sortable="props.sortable"
        >
          <template slot-scope="scope">
            <span v-if="'reno' == props.prop">{{ scope.$index + 1 }}</span>
            <span v-else-if="'createTime' == props.prop">{{scope.row[props.prop]|mileSecondToDate}}</span>
            <span v-else-if="'modifyTime' == props.prop">{{scope.row[props.prop]|mileSecondToDate}}</span>
            <span v-else>{{ scope.row[props.prop] }}</span>
          </template>
        </el-table-column>
      </template>

      <!--操作列内的按钮-->
      <template slot="operateCell" slot-scope="props">
        <el-table-column
          :fixed="props.fixed"
          :label="props.label"
          width="120"
          class-name="operateCell"
        >
          <template slot-scope="scope">
            <el-button
              title="设置权限"
              size="small"
              type="primary"
              icon="icon-authority"
              class="ake-icon-font"
              v-if="isPermmited('PLATFORM:ROLE:SETRES')"
              @click="toOpenPrivilege(scope.row)"
              plain
            ></el-button>
            <el-button
              title="编辑"
              size="small"
              type="primary"
              icon="icon-edit"
              class="ake-icon-font"
              v-if="isPermmited('PLATFORM:ROLE:UPDATE')"
              @click="toOpenEditRole(scope.row)"
              plain
            ></el-button>
            <el-button
              title="删除"
              size="small"
              type="danger"
              icon="icon-delete"
              class="ake-icon-font"
              v-if="isPermmited('PLATFORM:ROLE:DEL')"
              @click="toOpenDeleteRole(scope.row)"
              plain
            ></el-button>
          </template>
        </el-table-column>
      </template>
    </multi-fun-table>

    <!---->
    <table-pagination :size="total" :cur-page="pageNumber" @backData="getPagination"></table-pagination>

    <!--modal-->
    <!--至少选择一项  modal-->
    <basic-modal ref="voidTipModal" bodyTxt="请至少选择一项">
      <h3 slot="title">温馨提示</h3>
      <div class="modal-footer" slot="modal-footer">
        <button class="ake_btn ake_btn_text modal-close" @click="closed('voidTipModal')">关闭</button>
      </div>
    </basic-modal>

    <!--编辑角色-->
    <basic-modal ref="roleRowModal" width="600" customeClass="role-row-modal" static="true">
      <h3 slot="title">编辑角色</h3>
      <div class="modal-body" slot="modal-body">
        <el-form
          ref="roleForm"
          :model="roleForm"
          :rules="rules"
          label-position="left"
          label-width="100px"
          style="width: 350px"
        >
          <el-form-item label="角色名称" prop="name">
            <el-input class="first-item" v-model="roleForm.name"></el-input>
          </el-form-item>
          <el-form-item label="描述" prop="remark">
            <el-input type="textarea" class="first-item" v-model="roleForm.remark"></el-input>
          </el-form-item>
        </el-form>
      </div>
      <div class="modal-footer" slot="modal-footer">
        <button class="ake_btn ake_btn_text ake_btn_confirm" @click.stop="saveRole('roleForm')">确认</button>
        <button class="ake_btn ake_btn_text modal-close" @click="closed('roleRowModal')">取消</button>
      </div>
    </basic-modal>

    <!--选择权限树-->
    <basic-modal
      ref="setPrivilegeModal"
      width="500"
      customeClass="select-Privilege-modal"
      static="true"
    >
      <h3 slot="title">设置权限</h3>
      <div class="modal-body" slot="modal-body">
        <div class="allcheck-box">
          <el-checkbox v-model="isAllCheck" @change="checkAllOrNo">全选/反选</el-checkbox>
          <span>选中{{checkedSum}}项</span>
        </div>
        <div class="common-tree modal-tree-box">
          <ul id="privilegeTree" name="privilegeTree" class="ztree"></ul>
        </div>
      </div>
      <div class="modal-footer" slot="modal-footer">
        <button
          type="button"
          class="ake_btn ake_btn_text ake_btn_confirm"
          @click="SetPrivilege('privilegeTree')"
        >确认</button>
        <button class="ake_btn ake_btn_text modal-close" @click="closed('setPrivilegeModal')">取消</button>
      </div>
    </basic-modal>

    <!-- 新增角色new -->
    <el-dialog title="新增角色" :visible.sync="dialogVisibleForRole" width="720px" class="zb-dialog">
      <div class="parkinglot-showInfo-content main-content-box">
        <div class="top-tab-box">
          <div class="tab-item" :class="{'active':tabIndexForRole==1}" @click="tabIndexForRole=1">
            <span>1</span>
            <span>创建角色</span>
          </div>
          <div class="tab-item" :class="{'active':tabIndexForRole==2}" @click="tabIndexForRole=2">
            <span>2</span>
            <span>设置权限</span>
          </div>
        </div>

        <div class="modal-box-inner" style="width: 500px; margin: 0 auto">
          <div class="add-role-box" v-show="tabIndexForRole==1">
            <el-form
              ref="addRoleForm"
              :model="addRoleForm"
              :rules="roleRules"
              label-position="left"
              label-width="100px"
            >
              <el-form-item label="角色名称" prop="name">
                <el-input class="first-item" v-model="addRoleForm.name"></el-input>
              </el-form-item>
              <el-form-item label="描述" prop="remark">
                <el-input type="textarea" class="first-item" v-model="addRoleForm.remark" rows="3"></el-input>
              </el-form-item>
            </el-form>
          </div>
          <div class="setup-role-tree-box" v-show="tabIndexForRole==2">
            <ul id="privilegeTree" name="privilegeTree" class="ztree"></ul>
            <div class="addNewRole-allcheck-box">
              <el-checkbox v-model="isAllCheck" @change="checkAllOrNo">全选/反选</el-checkbox>
              <span>选中{{checkedSum}}项</span>
            </div>
          </div>
        </div>
      </div>
      <span slot="footer">
        <el-button
          size="medium"
          plain
          @click="dialogVisibleForRole = false"
          v-if="tabIndexForRole==1"
        >取 消</el-button>
        <el-button size="medium" plain @click="tabIndexForRole--" v-else-if="tabIndexForRole==2">
          <i class="el-icon-arrow-left"></i>上一步
        </el-button>
        <el-button
          type="primary"
          size="medium"
          @click="tabIndexForRole++"
          v-if="tabIndexForRole==1"
        >
          下一步
          <i class="el-icon-arrow-right el-icon--right"></i>
        </el-button>
        <el-button
          type="primary"
          size="medium"
          @click="saveAddRoleModal('addRoleForm')"
          v-else-if="tabIndexForRole==2"
        >完成</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import common from "@mixins/common.js";
import stardardList from "@mixins/tables/stardardList.js";

//modal
import invokeModal from "@mixins/modal/invokeModal.js";
import "../../assets/js/libs/jquery.ztree.core.min.js";
import "../../assets/js/libs/jquery.ztree.excheck.min.js";
// import BigPicModal from '@components/widgets/BigPicModal.vue'

// image
// import images from '@mixins/image.js'

// 引进vue的js
import Role from "./js/Role.js";

export default {
  name: "authzRole",
  mixins: [common, stardardList, invokeModal, Role],
  data() {
    return {
      total: 0,
      fixedCols: 0,
      searchList: [
        {
          index: 0,
          isShow: false,
          type: "text",
          name: "name",
          text: "角色名称",
          value: ""
        }
      ],
      theadsInfo: [
        { index: 0, isShow: false, prop: "reno", text: "序号", width: 68 },
        {
          index: 1,
          isShow: false,
          prop: "name",
          text: "角色名称",
          minWidth: 50
        },
        { index: 2, isShow: false, prop: "remark", text: "描述", minWidth: 50 },
        {
          index: 3,
          isShow: false,
          prop: "createTime",
          text: "创建时间",
          minWidth: 80
        },
        {
          index: 4,
          isShow: false,
          prop: "modifyTime",
          text: "最后更新时间",
          minWidth: 80
        }
      ],
      tbodysInfo: []
    };
  }
};
</script>

<style scoped lang="less">
.modal-box-inner {
  height: 400px;
  display: flex;
  padding-top: 30px;
  padding-bottom: 30px;
}
.allcheck-box {
  width: 300px;
  margin: 0 auto;
  margin-bottom: 10px;
}

.modal-tree-box {
  width: 300px;
  margin: 0 auto;
}
.allcheck-box,
.addNewRole-allcheck-box {
  display: flex;
  justify-content: space-between;
  background: #fff;
  margin-top: 20px;
}
.top-tab-box {
  height: 60px;
  display: -ms-flexbox;
  display: flex;
  margin-top: -30px;
  margin-left: -20px;
  margin-right: -20px;
}
.top-tab-box .tab-item {
  height: 60px;
  line-height: 60px;
  -ms-flex: 1;
  flex: 1;
  text-align: center;
  border-bottom: 1px solid #d7dce2;
  display: -ms-flexbox;
  display: flex;
  -ms-flex-align: center;
  align-items: center;
  -ms-flex-pack: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
}

.top-tab-box .tab-item.active {
  span:first-child {
    background: #5995d8;
    color: #ffffff;
  }
  span:last-child {
    color: #5995d8;
  }

  &:after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 3px;
    background: #5995d8;
  }
}

.top-tab-box .tab-item span:first-child {
  width: 24px;
  height: 24px;
  line-height: 24px;
  background: #d7dce2;
  text-align: center;
  border-radius: 12px;
  color: #ffffff;
}
.top-tab-box .tab-item span:last-child {
  padding-left: 10px;
  font-size: 14px;
  color: #999999;
}
</style>

<style>
.modal-container {
  position: relative;
}
</style>


<style lang="less" scoped>
@import "../../assets/less/libs/zTreeStyle.css";
.setup-role-tree-box {
  width: 300px;
  height: 100%;
  margin: auto;
  #privilegeTree {
    height: 100%;
    overflow-y: scroll;
  }
}

.setup-role-tree-box {
  padding-top: 30px;
}
.dialog-footer {
  width: 100%;
  text-align: right;
  .footer-tip-box {
    .red-tip {
      color: #d0021b;
    }
    .footer-text-tip {
      color: #666666;
    }
  }
}

.el-input,
.el-textarea__inner {
  width: 320px;
}

.role-row-modal {
  .first-item {
    width: 240px;
  }
}
.role-select {
  width: 240px;
}

//权限树样式start
.modal-body {
  max-height: 800px;
  overflow-y: auto;
}
.select-Privilege-modal {
  padding-bottom: 30px;
  .modal-body {
    max-height: 400px;
  }
}
//权限树样式end
</style>
